package com.ruoyi.websocket.config;

import com.ruoyi.websocket.handler.ChatMsgWebSocketHandle;
import com.ruoyi.websocket.handler.ChatWebSocketHandle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
 * @ClassName WebSocketConfig
 * @Description 配置类
 * @Author li yang
 * @Date 2025/9/8 11:54
 * @Version 1.0
 */
@Component
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    @Autowired
    private ChatWebSocketHandle webSocketHandler;

    @Autowired
    private ChatMsgWebSocketHandle chatMsgwebSocketHandler;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(chatMsgwebSocketHandler, "/webSocket/chat/{openId}")
                // 如果前端和后端在不同的域，配置跨域
                .setAllowedOrigins("*");
    }
}
